//
//  MYSetUpViewController.m
//  ZHIDOU
//
//  Created by 向礼 on 2018/12/25.
//  Copyright © 2018 向礼. All rights reserved.
//

#import "MYSetUpViewController.h"
#import "MYSetUpCell.h"
#import "changePhoneNumberViewController.h"
#import "ChangePasswordViewController.h"

@interface MYSetUpViewController ()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic ,strong)UITableView *tableView ;
@property (nonatomic ,copy)NSArray *dataSouce;
@property (nonatomic ,copy)NSArray *neiRongArr;
@end

@implementation MYSetUpViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    _dataSouce = @[@[@"更换手机号",@"修改密码"],
                   @[@"清除缓存",@"联系我们"],
                   @[@"退出账号"]];
    _neiRongArr = @[@[@"13145678901",@""],
                    @[@"39k",@""],
                    @[@""]];
    [self setUpViews];
    // Do any additional setup after loading the view.
}

#pragma mark - UI
- (void)setUpViews {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, ZD_screenHeight - self.bottomSafeAreaInsets) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellEditingStyleNone;
    self.tableView.backgroundColor = ZD_backgroundColor;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"MYSetUpCell" bundle:nil] forCellReuseIdentifier:@"MYSetUpCell"];
    [self.view addSubview:self.tableView];
}


#pragma mark -  TableViewDelegete
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arr = self.dataSouce[section];
    return arr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSouce.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MYSetUpCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYSetUpCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleStr = self.dataSouce[indexPath.section][indexPath.row];
    cell.neiRongStr = self.neiRongArr[indexPath.section][indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 12;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, 12)];
    sectionView.backgroundColor = ZD_backgroundColor;
    return sectionView;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        changePhoneNumberViewController *change= [[changePhoneNumberViewController alloc]init];
        [self.navigationController pushViewController:change animated:YES];
    }else if (indexPath.section == 0 && indexPath.row == 1){
        ChangePasswordViewController *changepassWord  = [[ChangePasswordViewController alloc]init];
        [self.navigationController pushViewController:changepassWord animated:YES];
    }

}

@end
